package jdos.ints;

import jdos.gui.Main;
import jdos.hardware.*;

public class Int10_modes {
    static public final int _EGA_HALF_CLOCK		=0x0001;
    static public final int  _EGA_LINE_DOUBLE	=0x0002;
    static public final int  _VGA_PIXEL_DOUBLE	=0x0004;

    static public final int  SEQ_REGS =0x05;
    static public final int  GFX_REGS =0x09;
    static public final int  ATT_REGS =0x15;

    public static Int10.VideoModeBlock ModeList_VGA[]={

        new Int10.VideoModeBlock( 0x013  ,0   ,320 ,200 ,40 ,25 ,8 ,8  ,1 ,0xA0000 ,0x2000),

    };

    public static Int10.VideoModeBlock CurMode;

	private static boolean SetCurMode(int mode) {

		CurMode = ModeList_VGA[0];
		return true;
	}

    private static void FinishSetMode(boolean clearmem) {
        /* Clear video memory if needs be */

        /* Setup the BIOS */
        if (CurMode.mode<128) Memory.real_writeb(Int10.BIOSMEM_SEG,Int10.BIOSMEM_CURRENT_MODE,CurMode.mode);
        else Memory.real_writeb(Int10.BIOSMEM_SEG,Int10.BIOSMEM_CURRENT_MODE,CurMode.mode-0x98);	//Looks like the s3 bios
        Memory.real_writew(Int10.BIOSMEM_SEG,Int10.BIOSMEM_NB_COLS,CurMode.twidth);
        Memory.real_writew(Int10.BIOSMEM_SEG,Int10.BIOSMEM_PAGE_SIZE,CurMode.plength);
        Memory.real_writew(Int10.BIOSMEM_SEG,Int10.BIOSMEM_CRTC_ADDRESS,((CurMode.mode==7 )|| (CurMode.mode==0x0f)) ? 0x3b4 : 0x3d4);
        Memory.real_writeb(Int10.BIOSMEM_SEG,Int10.BIOSMEM_NB_ROWS,(CurMode.theight-1));
        Memory.real_writew(Int10.BIOSMEM_SEG,Int10.BIOSMEM_CHAR_HEIGHT,CurMode.cheight);
        Memory.real_writeb(Int10.BIOSMEM_SEG,Int10.BIOSMEM_VIDEO_CTL,(0x60|(clearmem?0:0x80)));
        Memory.real_writeb(Int10.BIOSMEM_SEG,Int10.BIOSMEM_SWITCHES,0x09);

        // this is an index into the dcc table:
        //if (Dosbox.IS_VGA_ARCH())
        Memory.real_writeb(Int10.BIOSMEM_SEG,Int10.BIOSMEM_DCC_INDEX,0x0b);
        Memory.real_writed(Int10.BIOSMEM_SEG,Int10.BIOSMEM_VS_POINTER,Int10.int10.rom.video_save_pointers);

        // Set cursor shape

        // Set cursor pos for page 0..7
        Int10_char.INT10_SetCursorPos((short)0,(short)0,(short)0);
        // Set active page 0
        //Int10_char.INT10_SetActivePage((short)0);
        /* Set some interrupt vectors */

        Memory.RealSetVec(0x43,Int10.int10.rom.font_8_first);

        /* Tell mouse resolution change */
        Mouse.Mouse_NewVideoMode();
    }

public static boolean INT10_SetVideoMode(/*Bit16u*/int mode) {
	System.out.println("vgaMode:"+mode);
    Main.cmap[0] = 0;
    for (int r=1; r < 256; r ++) {
    	Main.cmap[r] = 0xFFFFFF;
    }
		SetCurMode(mode);

	FinishSetMode(true);

	return true;
}

}
